﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PloobsEngine.Publishers
{
    public class ConcreteSubject : ISubject
    {
        
        private IList<IObserver> _obsList = new List<IObserver>();

        #region ISubject Members

        public void Attach(IObserver obs)
        {
            _obsList.Add(obs);
            obs.AddSubject(this);
            
        }

        public void Dettach(IObserver obs)
        {
             _obsList.Remove(obs);
             obs.RemoveSubject(this);
            
        }

        public void DettachAll()
        {
            foreach (IObserver obs in _obsList)
            {
                obs.RemoveSubject(this);
            }
            _obsList.Clear();
            
        }

        public void Notify(Object obj)
        {
            foreach (IObserver obs in _obsList)
            {
                obs.Recieve(obj);
            }
        }

        #endregion

        #region ISubject Members


        public int ObserverNumber()
        {
            return _obsList.Count;
        }

        #endregion
    }
}
